{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3583ca8a-3696-441d-8bd3-ec3851f0be6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import csv\n",
    "import torch\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d96e98b4-964b-4046-84ce-b917f9408ea6",
   "metadata": {},
   "source": [
    "# 红酒数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a58b39d4-3f63-4a54-8153-875adfdc8c49",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4898, 12)\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import csv\n",
    "\n",
    "wine_path = r\"D:\\workspace\\deeplearning\\data\\4\\winequality.csv\"\n",
    "wine_numpy = np.loadtxt(wine_path, dtype=np.float32, delimiter=\";\", skiprows=1)\n",
    "print(wine_numpy.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e2723fba-bd6e-422d-ae00-f442a12fce9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((4898, 12),\n",
       " ['fixed acidity',\n",
       "  'volatile acidity',\n",
       "  'citric acid',\n",
       "  'residual sugar',\n",
       "  'chlorides',\n",
       "  'free sulfur dioxide',\n",
       "  'total sulfur dioxide',\n",
       "  'density',\n",
       "  'pH',\n",
       "  'sulphates',\n",
       "  'alcohol',\n",
       "  'quality'],\n",
       " numpy.ndarray)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col_list = next(csv.reader(open(wine_path), delimiter=\";\"))\n",
    "wine_numpy.shape, col_list, type(wine_numpy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "dfb83a56-b771-48d7-a31f-e58fd8f32d03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(torch.Size([4898, 12]), torch.float32)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wineq = torch.from_numpy(wine_numpy)\n",
    "wineq.shape, wineq.dtype"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "036cfb58-dcf7-4057-8267-4314103b4f37",
   "metadata": {},
   "source": [
    "# 准备共享单车数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "24106080-db1e-4880-87df-3ec6c31b666e",
   "metadata": {},
   "outputs": [],
   "source": [
    "bike_numpy = np.loadtxt(r\"D:\\workspace\\deeplearning\\data\\4\\bike-sharing\\hour-fixed.csv\",\n",
    "                        dtype=np.float32, \n",
    "                        delimiter=\",\", \n",
    "                        skiprows=1, \n",
    "                        converters= {1:lambda x : float(x[8:10])})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a02ce5f3-3964-4fb1-8187-42eb67c1db86",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[1.0000e+00, 1.0000e+00, 1.0000e+00,  ..., 3.0000e+00, 1.3000e+01,\n",
       "         1.6000e+01],\n",
       "        [2.0000e+00, 1.0000e+00, 1.0000e+00,  ..., 8.0000e+00, 3.2000e+01,\n",
       "         4.0000e+01],\n",
       "        [3.0000e+00, 1.0000e+00, 1.0000e+00,  ..., 5.0000e+00, 2.7000e+01,\n",
       "         3.2000e+01],\n",
       "        ...,\n",
       "        [1.7377e+04, 3.1000e+01, 1.0000e+00,  ..., 7.0000e+00, 8.3000e+01,\n",
       "         9.0000e+01],\n",
       "        [1.7378e+04, 3.1000e+01, 1.0000e+00,  ..., 1.3000e+01, 4.8000e+01,\n",
       "         6.1000e+01],\n",
       "        [1.7379e+04, 3.1000e+01, 1.0000e+00,  ..., 1.2000e+01, 3.7000e+01,\n",
       "         4.9000e+01]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bikes = torch.from_numpy(bike_numpy)\n",
    "bikes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "8f9dc8f8-5387-4d71-ad6e-699c6835b30d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "总租车次数: 3,292,679\n",
      "平均租车次数: 188\n",
      "最大租车次数: 977\n"
     ]
    }
   ],
   "source": [
    "# 租车总量\n",
    "# 最大租车量\n",
    "# 最小租车量\n",
    "# 平均租车量\n",
    "\n",
    "# 统计分析\n",
    "total_rental = bikes[:, 16]\n",
    "print(f\"总租车次数: {total_rental.sum().item():,.0f}\")\n",
    "print(f\"平均租车次数: {total_rental.mean().item():,.0f}\")\n",
    "print(f\"最大租车次数: {total_rental.max().item():,.0f}\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "yolotorch",
   "language": "python",
   "name": "yolotorch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
